package com.tj.jinzao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.tj.jinzao.R;
import com.tj.jinzao.common.Constant;
import com.tj.jinzao.model.GiftBean;

import java.util.List;

public class StartLiveAdapter extends Base_Adapter {
    private boolean mIsPeerToPeerMode;
    public StartLiveAdapter(Context context, List list, boolean isFirst,boolean mIsPeerToPeerMode) {
        super(context, list, isFirst);
        this.mIsPeerToPeerMode=mIsPeerToPeerMode;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            viewHolder=new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.start_live_bottom,null);
            viewHolder.img=convertView.findViewById(R.id.img);
            viewHolder.name=convertView.findViewById(R.id.name);
            viewHolder.money=convertView.findViewById(R.id.money);
            viewHolder.lay_bot=convertView.findViewById(R.id.lay_bot);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
       GiftBean giftBean= (GiftBean) getItem(position);
        if(giftBean!=null){
            if(mIsPeerToPeerMode){
                Glide.with(context).load(Constant.IMAGE_PREFIX + giftBean.getImgurl()).into(viewHolder.img);
                viewHolder.money.setText(giftBean.getScore()+"早币");
                viewHolder.name.setText(giftBean.getName());

            }else {
                Glide.with(context).load(Constant.IMAGE_PREFIX + giftBean.getGitImgurl()).into(viewHolder.img);
                viewHolder.name.setText(giftBean.getGitName());
                viewHolder.money.setText(giftBean.getCount()+"个");
            }
//            else {
//                //这段代码没用，现在请求服务器的，放在这里防止之后需要用本地的
//                viewHolder.img.setImageResource(giftBean.getResid());
//                viewHolder.money.setText(giftBean.getMoney());
//                viewHolder.name.setText(giftBean.getName());
                if(giftBean.isSelect()){
                    viewHolder.lay_bot.setBackgroundResource(R.drawable.grid_gift_ground);
                }else {
                    viewHolder.lay_bot.setBackgroundResource(R.drawable.grid_un_gift_ground);
                }
//
//            }
        }
        return convertView;
    }
    class ViewHolder{
        ImageView img;
        TextView name,money;
        LinearLayout lay_bot;

    }
}
